/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.fontelet.source.comercial.beans;

import com.fontelet.source.entidade.beans.Entidade;
import com.fontelet.source.gerencial.beans.Empresa;
import java.io.Serializable;
import java.sql.Time;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author Hexa2
 */
@Entity
@Table(uniqueConstraints = {@UniqueConstraint(columnNames={"empresa", "tipoPedido", "numero"})})
public class Pedido implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @OneToOne
    private Empresa empresa;
    @OneToOne
    private TipoPedido tipoPedido;
    private Long numero;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataInicial;
    private Time horaInicial;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataFinal;
    private Time horaFinal;
    @OneToOne
    private PedidoEndereco enderecoOrigem;
    @OneToOne
    private Entidade destinatario;
    @OneToOne
    private PedidoEndereco enderecoDestinatario;
    @OneToOne
    private Entidade transportador;
    @OneToOne
    private PedidoEndereco enderecoTransportador;
    @OneToOne
    private TipoOperacao tipoOperacao;
    @OneToMany(mappedBy = "pedido")
    private List<PedidoItem> pedidoItens;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pedido)) {
            return false;
        }
        Pedido other = (Pedido) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.fontelet.source.comercial.beans.Pedido[id=" + id + "]";
    }

}
